/**
 * 
 */
package com.fish.sight.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.fish.common.constant.QueryPage;
import com.fish.common.dao.BaseIbatisDao;
import com.fish.common.tag.Pager;
import com.fish.finance.po.Settlement;
import com.fish.sight.po.Sight;

/**
 * @author damian
 *
 */
public class SightDao extends BaseIbatisDao {
	@SuppressWarnings("unchecked")
	public Pager<Sight> selectSightWithPaging(Map<String,Object> param){
//		if(param!=null && param.get("postTimeEnd")!=null && !"".equals(param.get("postTimeEnd"))){
//			param.put("postTimeEnd", String.valueOf(param.get("postTimeEnd"))+" 23:59:59");
//		}
//		if(param!=null && param.get("updateTimeEnd")!=null && !"".equals(param.get("updateTimeEnd"))){
//			param.put("updateTimeEnd", String.valueOf(param.get("updateTimeEnd"))+" 23:59:59");
//		}
		Long count = 0L;
		Pager<Sight> pager = new Pager<Sight>();
		List<Sight> list=this.getSqlMapClientTemplate().queryForList("SIGHT.selectSightWithPaging",param);
		count=(Long)this.getSqlMapClientTemplate().queryForObject("SIGHT.countSightWithPaging",param);
		pager.setData(list);
		pager.setCount(count.intValue());
		return pager;
	}
	
	public Long insertSight(Sight obj){
		return (Long)this.getSqlMapClientTemplate().insert("SIGHT.insertSight", obj);
	}
	
	public Sight selectSightById(String id){
		return (Sight)this.getSqlMapClientTemplate().queryForObject("SIGHT.selectSightById", id);
	}
	
	public boolean updateSight(Sight obj){
		int changedCount=this.getSqlMapClientTemplate().update("SIGHT.updateSight", obj);
		if(changedCount>0){
			return true;
		}
		return false;
	}
	
	public boolean deleteSight(String id,String updateUserId){
		Map<String,Object> param=new HashMap<String,Object>();
		param.put("sightId", id);
		param.put("updateUserId", updateUserId);
		int changedCount=this.getSqlMapClientTemplate().delete("SIGHT.deleteSight", param);
		if(changedCount>0){
			return true;
		}
		return false;
	}
	
	public Long querySightCountByObject(Sight sight){
		return  (Long) this.getSqlMapClientTemplate().queryForObject("SIGHT.countSightWithPaging", sight);
	}
	
	public  List<Sight> querySightByObject(Sight sight,QueryPage queryPage){
		sight.setBeginItem(queryPage.getBeginItem());
		sight.setEndItem(queryPage.getPageSize());
		return (List<Sight>) this.getSqlMapClientTemplate().queryForList("SIGHT.selectSightWithPaging", sight);
	}
}
